package j.framework.query.core;

import j.util.DES;
import j.util.StringUtils;
import j.util.json.JsonUtils;

import java.util.Map;

/**
 * 查询行上的操作，即操作列
 * Created by junhai on 2015/1/3.
 */
public class QueryAction implements java.io.Serializable {
    private Map<String,Object> customParametersMap = null;
    public Map<String,Object> getCustomParametersMap(){
        if(StringUtils.isNullOrEmpty(customParameters)){
            return null;
        }
        if(customParametersMap!=null){
            return customParametersMap;
        }
        try {
            customParametersMap = JsonUtils.parseMap(customParameters);
        }catch (Exception e){
            //指定的json参数错误，忽略
            customParameters = null;
            return null;
        }
        //处理des开头的key
        for(Map.Entry<String,Object> entry : customParametersMap.entrySet()){
            if(entry.getKey().startsWith("des")){
                entry.setValue(DES.encrypt(String.valueOf(entry.getValue())));
            }
        }
        return customParametersMap;
    }

    private String queryActionId;

    private String queryId;

    private String actionId; //对应的操作

    private String actionName;

    private String buttonType;//L-linkbutton；B-button

    private String iconKey;

    private String onClick;

    private String customParameters;

    private String generateMethodName;

    public String getQueryActionId() {
        return queryActionId;
    }
    public void setQueryActionId(String queryActionId) {
        this.queryActionId = queryActionId;
    }

    public String getQueryId() {
        return queryId;
    }
    public void setQueryId(String queryId) {
        this.queryId = queryId;
    }

    public String getActionId() {
        return actionId;
    }
    public void setActionId(String actionId) {
        this.actionId = actionId;
    }

    public String getActionName() {
        return actionName;
    }
    public void setActionName(String actionName) {
        this.actionName = actionName;
    }

    public String getButtonType() {
        return buttonType;
    }
    public void setButtonType(String buttonType) {
        this.buttonType = buttonType;
    }

    public String getIconKey() {
        return iconKey;
    }
    public void setIconKey(String iconKey) {
        this.iconKey = iconKey;
    }

    public String getOnClick() {
        return onClick;
    }
    public void setOnClick(String onClick) {
        this.onClick = onClick;
    }

    public String getCustomParameters() {
        return customParameters;
    }
    public void setCustomParameters(String customParameters) {
        this.customParameters = customParameters;
    }

    public String getGenerateMethodName() {
        return generateMethodName;
    }
    public void setGenerateMethodName(String generateMethodName) {
        this.generateMethodName = generateMethodName;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        QueryAction that = (QueryAction) o;

        if (queryActionId != null ? !queryActionId.equals(that.queryActionId) : that.queryActionId != null)
            return false;

        return true;
    }

    @Override
    public int hashCode() {
        return queryActionId != null ? queryActionId.hashCode() : 0;
    }
}
